package com.ruoyi.system.controller;

import java.io.IOException;
import java.util.List;

import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.utils.file.FileUploadUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.tomcat.jni.FileInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TRoom;
import com.ruoyi.system.service.ITRoomService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * Controller
 * @date 2021-03-24
 */
@Controller
@RequestMapping("/system/room")
public class TRoomController extends BaseController
{
    private String prefix = "system/room";

    @Autowired
    private ITRoomService tRoomService;

    @GetMapping()
    public String room()
    {
        return prefix + "/room";
    }

    /**
     * 查询
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TRoom tRoom)
    {
        startPage();
        List<TRoom> list = tRoomService.selectTRoomList(tRoom);
        return getDataTable(list);
    }

    /**
     * 导出
     */
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TRoom tRoom)
    {
        List<TRoom> list = tRoomService.selectTRoomList(tRoom);
        ExcelUtil<TRoom> util = new ExcelUtil<TRoom>(TRoom.class);
        return util.exportExcel(list, "room");
    }

    /**
     * 新增
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存
     */
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TRoom tRoom)
    {
        return toAjax(tRoomService.insertTRoom(tRoom));
    }

    /**
     * 修改
     */
    @GetMapping("/edit/{roomId}")
    public String edit(@PathVariable("roomId") Long roomId, ModelMap mmap)
    {
        TRoom tRoom = tRoomService.selectTRoomById(roomId);
        mmap.put("tRoom", tRoom);
        return prefix + "/edit";
    }

    /**
     * 修改保存
     */
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TRoom tRoom)
    {
        return toAjax(tRoomService.updateTRoom(tRoom));
    }

    /**
     * 删除
     */
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tRoomService.deleteTRoomByIds(ids));
    }

}